// import dayjs from 'dayjs'
// import 'dayjs/locale/zh-cn'
// dayjs.locale('zh-cn')
// export const chatDay = (time, time2) => { //time - 前  time2 - 后 source-list-chat
// 	let duration = time2 - time
// 	if (duration <= 1000 * 60) {
// 		return '刚刚'
// 	} else {
// 		let today = dayjs(new Date().getTime()).format('DD/MM/YYYY').split('/')
// 		let userDate = dayjs(time).format('DD/MM/YYYY').split('/')
// 		if (today[0] == userDate[0] && today[1] == userDate[1] && today[2] == userDate[2]) {
// 			return dayjs(time).format('A h:mm')
// 		}
// 		else if ((Number(today[0]) - Number(userDate[0]) == 1) && today[1] == userDate[1] && today[2] == userDate[2]) {
// 			return '昨天 ' + dayjs(time).format('HH:MM')
// 		}
// 		else {
// 			return dayjs(time).format('YYYY/MM/DD HH:MM')
// 		}
// 	}
// }

// export const chatTime = (time) => {
// 	let today = timestampToYMD(new Date().getTime()).split('/')
// 	let userDate = timestampToYMD(time).split('/')
// 	if (today[2] == userDate[2] && today[1] == userDate[1] && today[0] == userDate[0]) {
// 		return '今天'
// 	}
// 	else if ((Number(today[2]) - Number(userDate[2]) == 1) && today[1] == userDate[1] && today[0] == userDate[0]) {
// 		return '昨天'
// 	}
// 	else {
// 		return "其他"
// 	}
// }

export const chatTime = (time) => {
	let today = timestampToYMD(new Date().getTime())
	let userDate = timestampToYMD(time)
	if (today[0] == userDate[0] && today[1] == userDate[1] && today[2] == userDate[2]) {
		return `${zeroAdd(userDate[3])}:${zeroAdd(userDate[4])}`
	}
	else if (today[0] == userDate[0] && today[1] == userDate[1] && (Number(today[2]) - Number(userDate[2]) == 1)) {
		return `昨天 ${zeroAdd(userDate[3])}:${zeroAdd(userDate[4])}`
	}
	else if(today[0] == userDate[0]){
		return `${zeroAdd(userDate[1])}月${zeroAdd(userDate[2])}日 ${zeroAdd(userDate[3])}:${zeroAdd(userDate[4])}`
	}
	else {
		return `${zeroAdd(userDate[0])}/${zeroAdd(userDate[1])}/${zeroAdd(userDate[2])} ${zeroAdd(userDate[3])}:${zeroAdd(userDate[4])}`
	}
}
function timestampToYMD(timestamp) {
	const date = new Date(timestamp); // 将时间戳转换成毫秒
	const year = date.getFullYear();
	const month = date.getMonth() + 1;
	const day = date.getDate();
	const hour = date.getHours();
	const minute = date.getMinutes();
	const second = date.getSeconds() 
	// return `${year}/${month}/${day}`;
	return [year,month,day,hour,minute,second]
}
function zeroAdd(num){
	if(Number(num)<10){
		return "0"+num
	}else{
		return num
	}
}